/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package gbbmgmt;

import java.util.*;
//import org.jdesktop.application.Action;
import javax.swing.JOptionPane;

/**
 *
 * @author dchapman
 */
public class Actions {
    public static String results = null;

    public static String ReturnInfo(String str){
        String retstr = null;
        if (str.equals("Current Inventory")){
            retstr = "Open a window of current beer inventory values in stock.";
        }
        if (str.equals("Customer Data")){
            retstr = "View/Add/Modify Customer Information in Database.";
        }
        if (str.equals("Sales Order")){
            retstr = "View/Modify Sales Orders in Database.";
        }
        if (str.equals("New Sales Order")){
            retstr = "Create a New Sales Orders in Database.";
        }
        if (str.equals("Tap Room Keg Sale")){
            retstr = "Create/Edit/Modify a new Taproom Keg Sale.";
        }
        if (str.equals("Tap Room Movement")){
            retstr = "Create a new Taproom Movement.";
        }
        if (str.equals("Overdue Sales Orders")){
            retstr = "Run a report to capture all overdue SalesOrders.";
        }
        if (str.equals("Brew Notes")){
            retstr = "View/Edit/Create Notes for a brew.";
        }
        if (str.equals("Recipes")){
            retstr = "View/Edit/Create Recipes.";
        }
        if (str.equals("Beers")){
            retstr = "View/Edit/Create Beers.";
        }
        if (str.equals("Movement Log")){
            retstr = "Add a Movement to the system.";
        }
        if (str.equals("Tank Status")){
            retstr = "View Status of Tanks.";
        }
        if (str.equals("Barrel Movement")){
            retstr = "Create a Barrel Movement";
        }
        if (str.equals("Vendor Information")){
            retstr = "Create/Edit/Modify Vendor Records";
        }
        if (str.equals("Malt Information")){
            retstr = "Create/Edit/Modify Malt Records";
        }
        if (str.equals("Hop Information")){
            retstr = "Create/Edit/Modify Hop Records";
        }
        if (str.equals("Purchase Order Records")){
            retstr = "View/Modify/Create Purchase Order Records";
        }
        if (str.equals("Inventory Information")){
            retstr = "View/Modify General Inventory Records";
        }
        if (str.equals("Malt Inventory Verification")){
            retstr = "Update Malt Inventory Records";
        }
        if (str.equals("Hop Inventory Verification")){
            retstr = "Update Hop Inventory Records";
        }
        if (str.equals("General Inventory Verification")){
            retstr = "Update General Inventory Records";
        }
        if (str.equals("User Admin")){
            retstr = "Add/Remove/Modify Users.";
        }
        if (str.equals("Cost Code")){
            retstr = "Add/Remove/Modify Cost Codes.";
        }
        if (str.equals("Discount Code")){
            retstr = "Add/Remove/Modify Discount Codes.";
        }
        if (str.equals("Sales Report")){
            retstr = "View Sales Report for Selected Dates.";
        }
        if (str.equals("Brewing Forcast Report")){
            retstr = "Forcast Brewing Schedule Based on Current Sales.";
        }
        if (str.equals("Brewery Tools")){
            retstr = "Various tools for brewery tasks (i.e. abv calulator, etc).";
        }
        if (str.equals("Inventory Control")){
            retstr = "View / Modify Beer Inventory.";
        }
        if (str.equals("Yeast Information")){
            retstr = "View / Modify Yeast Information.";
        }
        if (str.equals("Vessel Setup")){
            retstr = "View / Modify vessels in brewhouse.";
        }
        if (str.equals("Keg Split")){
            retstr = "Split a keg into smaller kegs.";
        }
        if (str.equals("Wearhouse Setup")){
            retstr = "Setup Wearhouses for use in inventory.";
        }
        if (str.equals("Trial Brew")){
            retstr = "Run a Trial Brew Report.";
        }
        if (str.equals("Movement History")){
            retstr = "View Movement History.";
        }
        if (str.equals("Brewers Report Of Operations")){
            retstr = "Run a Brewers Report of Operations.";
        }
        if (str.equals("Colorado Tax Report")){
            retstr = "Run a monthly tax report for the state of Colorado";
        }

        return retstr;
    }

    public static String ReturnIcon(String str){
        String retstr = null;
        if (str.equals("Current Inventory")){
            retstr = "Inv.PNG";
        } else if (str.equals("Customer Data")){
            retstr = "Cust.PNG";
        } else if (str.equals("Sales Order")){
            retstr = "SORec.PNG";
        } else if (str.equals("New Sales Order")){
            retstr = "SO.PNG";
        } else if (str.equals("Tap Room Keg Sale")){
            retstr = "TRSale.PNG";
        } else if (str.equals("Tap Room Movement")){
            retstr = "TRMove.PNG";
        } else if (str.equals("Overdue Sales Orders")){
            retstr = "Report.PNG";
        } else if (str.equals("Brew Notes")){
            retstr = "BNotes.PNG";
        } else if (str.equals("Recipes")){
            retstr = "Recipe.PNG";
        } else if (str.equals("Beers")){
            retstr = "Beer.PNG";
        } else if (str.equals("Movement Log")){
            retstr = "Move.PNG";
        } else if (str.equals("Tank Status")){
            retstr = "Ferm.PNG";
        } else if (str.equals("Barrel Movement")){
            retstr = "Barrel.PNG";
        } else if (str.equals("Vendor Information")){
            retstr = "Vend.PNG";
        } else if (str.equals("Malt Information")){
            retstr = "Malt.PNG";
        } else if (str.equals("Hop Information")){
            retstr = "Hop.PNG";
        } else if (str.equals("Purchase Order Records")){
            retstr = "PO.PNG";
        } else if (str.equals("Inventory Information")){
            retstr = "Inventory.PNG";
        } else if (str.equals("Malt Inventory Verification")){
            retstr = "MaltInv.PNG";
        } else if (str.equals("Hop Inventory Verification")){
            retstr = "HopInv.PNG";
        } else if (str.equals("General Inventory Verification")){
            retstr = "Inventory.PNG";
        } else if (str.equals("User Admin")){
            retstr = "Admin.PNG";
        } else if (str.equals("Cost Code")){
            retstr = "Cost.PNG";
        } else if (str.equals("Discount Code")){
            retstr = "Disc.PNG";
        } else if (str.equals("Sales Report")) {
            retstr = "Graph.PNG";
        } else {
            retstr = "Report.PNG";
        }
        return retstr;
    }

    public static void CallFunction(String str) {
        if (str.equals("Current Inventory")){
            PrintInventory();
        }
        if (str.equals("Customer Data")){
            CustomerData();
        }
        if (str.equals("Sales Order")){
            SalesOrderData();
        }
        if (str.equals("New Sales Order")){
            NewSalesOrder();
        }
        if (str.equals("Tap Room Keg Sale")){
            TapRoomKegSale();
        }
        if (str.equals("Tap Room Movement")){
            TapRoomMovement();
        }
        if (str.equals("Overdue Sales Orders")){
            OverdueSOReport();
        }
        if (str.equals("Brew Notes")){
            BrewNotes();
        }
        if (str.equals("Recipes")){
            Recipes();
        }
        if (str.equals("Beers")){
            Beers();
        }
        if (str.equals("Movement Log")){
            Movement();
        }
        if (str.equals("Tank Status")){
            Status();
        }
        if (str.equals("Barrel Movement")){
            BarrelMove();
        }
        if (str.equals("Vendor Information")){
            Vendor();
        }
        if (str.equals("Malt Information")){
            Malt();
        }
        if (str.equals("Hop Information")){
            Hop();
        }
        if (str.equals("Purchase Order Records")){
            PurchaseOrder();
        }
        if (str.equals("Inventory Information")){
            Inventory();
        }
        if (str.equals("Malt Inventory Verification")){
            UpdateMalt();
        }
        if (str.equals("Hop Inventory Verification")){
            UpdateHops();
        }
        if (str.equals("General Inventory Verification")){
            UpdateGeneral();
        }
        if (str.equals("User Admin")){
            Users();
        }
        if (str.equals("Cost Code")){
            Cost();
        }
        if (str.equals("Discount Code")){
            Discount();
        }
        if (str.equals("Sales Report")){
            SalesRep();
        }
        if (str.equals("Brewing Forcast Report")){
            BrewForcast();
        }
        if (str.equals("Brewery Tools")){
            BreweryTools();
        }
        if (str.equals("Inventory Control")){
            InvControl();
        }
        if (str.equals("Yeast Information")){
            Yeast();
        }
        if (str.equals("Vessel Setup")){
            Vessels();
        }
        if (str.equals("Keg Split")){
            KegSplit();
        }
        if (str.equals("Wearhouse Setup")){
            Wearhouse();
        }
        if (str.equals("Trial Brew")){
            TrialBrew();
        }
        if (str.equals("Movement History")){
            MovementHistory();
        }
        if (str.equals("Brewers Report Of Operations")){
            OpReport();
        }
        if (str.equals("Colorado Tax Report")){
            COTaxReport();
        }
    }


    //User Level 4 (all People)
    private static void PrintInventory(){
        //Run a query for inventory.
        DBA.openDBCon();
        DBA.PerformInventoryQuery();
        DBA.closeDBCon();
    }

    private static void BrewForcast(){
        BrewForcastFrame newFrame = new BrewForcastFrame();
        newFrame.pack();
        newFrame.setLocation(250,250);
        newFrame.setTitle("Brewing Forcast");
        newFrame.setVisible(true);
    }

    private static void BreweryTools(){
        ToolsFrame newFrame = new ToolsFrame();
        newFrame.pack();
        newFrame.setLocation(250,250);
        newFrame.setTitle("Brewery Tools");
        newFrame.setVisible(true);
    }

    private static void TapRoomKegSale(){
        TapRoomKegSaleForm newFrame = new TapRoomKegSaleForm();
        newFrame.pack();
        newFrame.setLocation(250,250);
        newFrame.setTitle("Tap Room Keg Sales");
        newFrame.setVisible(true);
        newFrame.LoadList();
    }
    
    private static void TapRoomMovement(){
        TapRoomFrame newFrame = new TapRoomFrame();
        newFrame.pack();
        newFrame.setLocation(250,250);
        newFrame.setTitle("Tap Room Movement");
        newFrame.setVisible(true);
        newFrame.LoadList();
    }

    private static void Inventory(){
        SuppliesFrame newFrame = new SuppliesFrame();
        newFrame.pack();
        newFrame.setLocation(250,250);
        newFrame.setTitle("Inventory");
        newFrame.setVisible(true);
        newFrame.LoadList();
    }

    private static void MovementHistory(){
        MovementViewFrame newFrame = new MovementViewFrame();
        newFrame.pack();
        newFrame.setLocation(250,250);
        newFrame.setTitle("Movement History");
        newFrame.setVisible(true);
        newFrame.LoadList();
    }

    //User Level 3 (Buisiness Staff)
    private static void CustomerData(){
        if(Global.userLevel < 4){
            CustomerFrame newFrame = new CustomerFrame();
            newFrame.pack();
            newFrame.setLocation(250,250);
            newFrame.setTitle("Customer Information");
            newFrame.setVisible(true);
            newFrame.LoadList();
        } else {
            JOptionPane.showMessageDialog(null, "You do not have access to this item.");
        }
    }

    private static void SalesOrderData(){
        if(Global.userLevel < 4){
            SalesOrderFrame newFrame = new SalesOrderFrame();
            newFrame.pack();
            newFrame.setLocation(250,250);
            newFrame.setTitle("Sales Order Data");
            newFrame.setVisible(true);
            newFrame.LoadList();
        } else {
            JOptionPane.showMessageDialog(null, "You do not have access to this item.");
        }
    }

    private static void NewSalesOrder(){
        if(Global.userLevel < 4){
            NewSOFrame newFrame = new NewSOFrame();
            newFrame.pack();
            newFrame.setLocation(250,250);
            newFrame.setTitle("Enter New Sales Order");
            newFrame.setVisible(true);
            newFrame.LoadList();
        } else {
            JOptionPane.showMessageDialog(null, "You do not have access to this item.");
        }
    }

    private static void SalesRep(){
        if(Global.userLevel < 4){
            SalesReportFrame newFrame = new SalesReportFrame();
            newFrame.pack();
            newFrame.setLocation(250,250);
            newFrame.setTitle("Sales Report");
            newFrame.setVisible(true);
            newFrame.LoadList();
        } else {
            JOptionPane.showMessageDialog(null, "You do not have access to this item.");
        }
    }

    private static void Vendor(){
        if(Global.userLevel < 4){
            VendorFrame newFrame = new VendorFrame();
            newFrame.pack();
            newFrame.setLocation(250,250);
            newFrame.setTitle("Vendor Information");
            newFrame.setVisible(true);
            newFrame.LoadList();
        } else {
            JOptionPane.showMessageDialog(null, "You do not have access to this item.");
        }
    }

    //User Level 1 Management Level
    private static void Cost(){
        if(Global.userLevel < 2){
            CostFrame newFrame = new CostFrame();
            newFrame.pack();
            newFrame.setLocation(250,250);
            newFrame.setTitle("Cost Management");
            newFrame.setVisible(true);
            newFrame.LoadList();
        } else {
            JOptionPane.showMessageDialog(null, "You do not have access to this item.");
        }
    }
    private static void Discount(){
        if(Global.userLevel < 2){
            DiscountFrame newFrame = new DiscountFrame();
            newFrame.pack();
            newFrame.setLocation(250,250);
            newFrame.setTitle("Discount Management");
            newFrame.setVisible(true);
            newFrame.LoadList();
        } else {
            JOptionPane.showMessageDialog(null, "You do not have access to this item.");
        }
    }

    //User Level 0 Administrator level
    private static void Users(){
        if(Global.userLevel < 1){
            UserFrame newFrame = new UserFrame();
            newFrame.pack();
            newFrame.setLocation(250,250);
            newFrame.setTitle("User Management");
            newFrame.setVisible(true);
            newFrame.LoadList();
        } else {
            JOptionPane.showMessageDialog(null, "You do not have access to this item.");
        }
    }
    
    private static void Vessels(){
        if(Global.userLevel < 1){
            VesselFrame newFrame = new VesselFrame();
            newFrame.pack();
            newFrame.setLocation(250,250);
            newFrame.setTitle("Vessel Management");
            newFrame.setVisible(true);
            newFrame.LoadList();
        } else {
            JOptionPane.showMessageDialog(null, "You do not have access to this item.");
        }
    }

    private static void Wearhouse(){
        if(Global.userLevel < 1){
            WearhouseFrame newFrame = new WearhouseFrame();
            newFrame.pack();
            newFrame.setLocation(250,250);
            newFrame.setTitle("Wearhouse Management");
            newFrame.setVisible(true);
            newFrame.LoadList();
        } else {
            JOptionPane.showMessageDialog(null, "You do not have access to this item.");
        }
    }


    //User Level 2 Brewery Staff
    private static void UpdateMalt(){
        if(Global.userLevel < 3){
            InventoryUpdateFrame newFrame = new InventoryUpdateFrame();
            newFrame.pack();
            newFrame.setLocation(250,250);
            newFrame.setTitle("Malt Inventory Update");
            newFrame.setVisible(true);
            newFrame.SetInvNumber(1);
            newFrame.LoadTable();
        } else {
            JOptionPane.showMessageDialog(null, "You do not have access to this item.");
        }
    }
    private static void InvControl(){
        if(Global.userLevel < 3){
            BeerInvUpdateFrame newFrame = new BeerInvUpdateFrame();
            newFrame.pack();
            newFrame.setLocation(250,250);
            newFrame.setTitle("Beer Inventory Update");
            newFrame.setVisible(true);
            newFrame.LoadTable();
        } else {
            JOptionPane.showMessageDialog(null, "You do not have access to this item.");
        }
    }
    private static void UpdateHops(){
        if(Global.userLevel < 3){
            InventoryUpdateFrame newFrame = new InventoryUpdateFrame();
            newFrame.pack();
            newFrame.setLocation(250,250);
            newFrame.setTitle("Hop Inventory Update");
            newFrame.setVisible(true);
            newFrame.SetInvNumber(2);
            newFrame.LoadTable();
        } else {
            JOptionPane.showMessageDialog(null, "You do not have access to this item.");
        }
    }
    private static void UpdateGeneral(){
        if(Global.userLevel < 3){
            InventoryUpdateFrame newFrame = new InventoryUpdateFrame();
            newFrame.pack();
            newFrame.setLocation(250,250);
            newFrame.setTitle("General Inventory Update");
            newFrame.setVisible(true);
            newFrame.SetInvNumber(3);
            newFrame.LoadTable();
        } else {
            JOptionPane.showMessageDialog(null, "You do not have access to this item.");
        }
    }
    private static void PurchaseOrder(){
        if(Global.userLevel < 3){
            POFrame newFrame = new POFrame();
            newFrame.pack();
            newFrame.setLocation(250,250);
            newFrame.setTitle("Purchase Orders");
            newFrame.setVisible(true);
            newFrame.LoadList();
        } else {
            JOptionPane.showMessageDialog(null, "You do not have access to this item.");
        }
    }
    private static void BrewNotes(){
        if(Global.userLevel < 3){
            BrewNotesFrame newFrame = new BrewNotesFrame();
            newFrame.pack();
            newFrame.setLocation(250,50);
            newFrame.setTitle("Brewing Notes");
            newFrame.setVisible(true);
            newFrame.LoadList();
        } else {
            JOptionPane.showMessageDialog(null, "You do not have access to this item.");
        }
    }
    private static void Recipes(){
        if(Global.userLevel < 3){
            RecipeFrame newFrame = new RecipeFrame();
            newFrame.pack();
            newFrame.setLocation(250,250);
            newFrame.setTitle("Recipe Form");
            newFrame.setVisible(true);
            newFrame.LoadList();
        } else {
            JOptionPane.showMessageDialog(null, "You do not have access to this item.");
        }
    }
    private static void Beers(){
        if(Global.userLevel < 3){
            BeerEntryFrame newFrame = new BeerEntryFrame();
            newFrame.pack();
            newFrame.setLocation(250,250);
            newFrame.setTitle("Beer Form");
            newFrame.setVisible(true);
            newFrame.LoadList();
        } else {
            JOptionPane.showMessageDialog(null, "You do not have access to this item.");
        }
    }
    private static void Movement(){
        if(Global.userLevel < 3){
            MovementFrame newFrame = new MovementFrame();
            newFrame.pack();
            newFrame.setLocation(250,250);
            newFrame.setTitle("Movement Form");
            newFrame.setVisible(true);
            newFrame.LoadList();
        } else {
            JOptionPane.showMessageDialog(null, "You do not have access to this item.");
        }
    }
    private static void Status(){
        if(Global.userLevel < 3){
            StatusFrame newFrame = new StatusFrame();
            newFrame.pack();
            newFrame.setLocation(250,250);
            newFrame.setTitle("Tank Status");
            newFrame.setVisible(true);
            newFrame.LoadList();
        } else {
            JOptionPane.showMessageDialog(null, "You do not have access to this item.");
        }
    }
    private static void BarrelMove(){
        if(Global.userLevel < 3){
            BarrelMoveFrame newFrame = new BarrelMoveFrame();
            newFrame.pack();
            newFrame.setLocation(250,250);
            newFrame.setTitle("Barrel Movement");
            newFrame.setVisible(true);
            newFrame.LoadList();
        } else {
            JOptionPane.showMessageDialog(null, "You do not have access to this item.");
        }
    }
    private static void TrialBrew(){
        if(Global.userLevel < 3){
            TrialBrewFrame newFrame = new TrialBrewFrame();
            newFrame.pack();
            newFrame.setLocation(250,250);
            newFrame.setTitle("Trial Brew Report");
            newFrame.setVisible(true);
            newFrame.LoadList();
        } else {
            JOptionPane.showMessageDialog(null, "You do not have access to this item.");
        }
    }
    private static void Malt(){
        if(Global.userLevel < 3){
            MaltFrame newFrame = new MaltFrame();
            newFrame.pack();
            newFrame.setLocation(250,250);
            newFrame.setTitle("Malt Information");
            newFrame.setVisible(true);
            newFrame.LoadList();
        } else {
            JOptionPane.showMessageDialog(null, "You do not have access to this item.");
        }
    }
    private static void Hop(){
        if(Global.userLevel < 3){
            HopFrame newFrame = new HopFrame();
            newFrame.pack();
            newFrame.setLocation(250,250);
            newFrame.setTitle("Hop Information");
            newFrame.setVisible(true);
            newFrame.LoadList();
        } else {
            JOptionPane.showMessageDialog(null, "You do not have access to this item.");
        }
    }
    private static void Yeast(){
        if(Global.userLevel < 3){
            YeastFrame newFrame = new YeastFrame();
            newFrame.pack();
            newFrame.setLocation(250,250);
            newFrame.setTitle("Yeast Information");
            newFrame.setVisible(true);
            newFrame.LoadList();
        } else {
            JOptionPane.showMessageDialog(null, "You do not have access to this item.");
        }
    }
    private static void KegSplit(){
        if(Global.userLevel < 3){
            KegSplitFrame newFrame = new KegSplitFrame();
            newFrame.pack();
            newFrame.setLocation(250,250);
            newFrame.setTitle("Keg Split Screen");
            newFrame.setVisible(true);
            newFrame.LoadList();
        } else {
            JOptionPane.showMessageDialog(null, "You do not have access to this item.");
        }
    }
    private static void OpReport(){
        if(Global.userLevel < 3){
            BrewersOpReportFrame newFrame = new BrewersOpReportFrame();
            newFrame.pack();
            newFrame.setLocation(250,250);
            newFrame.setTitle("Brewers Report Of Operations");
            newFrame.setVisible(true);
            newFrame.LoadList();
        } else {
            JOptionPane.showMessageDialog(null, "You do not have access to this item.");
        }
    }
    private static void COTaxReport(){
        if(Global.userLevel < 3){
            COTaxFormFrame newFrame = new COTaxFormFrame();
            newFrame.pack();
            newFrame.setLocation(250,250);
            newFrame.setTitle("Colorado Tax Form");
            newFrame.setVisible(true);
            newFrame.LoadList();
        } else {
            JOptionPane.showMessageDialog(null, "You do not have access to this item.");
        }
    }

    public static void OverdueSOReport(){
        //Display new frame.
        ReportFrame newFrame = new ReportFrame();
        newFrame.pack();
        newFrame.setLocation(250,250);
        newFrame.setTitle("Over Due Sales Orders");
        newFrame.setVisible(true);
        
        ArrayList<String[]> Customers;
        ArrayList<String[]> OverDueCust = new ArrayList<String[]>();

        //Get todays date.
        java.util.Date dt = new java.util.Date();
        java.sql.Date todaysdate = new java.sql.Date( dt.getTime());

        //Find all overdue sales orders.
        String query = "SELECT SOId,SODate,SOCust FROM SalesOrder WHERE SOPaid < 1";
        DBA.openDBCon();
        Customers = DBA.RunSQLQuery(query);

        //Look up to see if it is past due or not.
        for(String s[] : Customers){
            DBA.GetCustomerData(s[2]);
            DBA.GetSalesOrderData(s[0]);

            String[] temp = new String[3];

            //Set up calendar.
            Calendar cal = Calendar.getInstance();
            cal.setTime(DBA.SODate);

            //Add appropriate time to calendar.
            cal.add(Calendar.DATE, DBA.CTerms);
            java.sql.Date due = new java.sql.Date(cal.getTime().getTime());

            if (todaysdate.after(due)){
                temp[0] = DBA.CName;
                temp[1] = due.toString();
                temp[2] = Integer.toString(DBA.SOId);
                OverDueCust.add(temp);
            }
        }

        newFrame.DisplayStrArr(OverDueCust);

        DBA.closeDBCon();


    }
}
